package com.hzhr.iot.device.aop.service;

import com.hzhr.iot.device.service.base.BaseService;
import com.hzhr.iot.device.service.util.CheckUtil;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Around;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import java.util.HashMap;
import java.util.Map;
import com.hzhr.iot.core.constant.Common_ErrorsEnum;
import com.hzhr.iot.core.exception.ServiceException;
import com.hzhr.iot.device.model.bkMeter.BkMeterPutModel;
import com.hzhr.iot.device.model.bkMeter.BkMeterDeleteModel;
import com.hzhr.iot.device.model.bkMeter.BkMeterPostModel;

@Aspect
@Component
@Order(2)
public class BkMeterServiceAspect extends BaseService {
    @Around("execution(* com.hzhr.iot.device.service.BkMeterService.put(..))")
    public Object put(ProceedingJoinPoint joinPoint) throws Throwable {
        Object[] args = joinPoint.getArgs();
        Map<String, String> header = (Map<String, String>) args[0];
        if (header == null) {
            header = new HashMap<>();
        }
        Map<String, Object> query = (Map<String, Object>) args[1];
        if (query == null) {
            query = new HashMap<>();
        }

        BkMeterPutModel body = (BkMeterPutModel)args[2];
        if (body == null) {
            throw new ServiceException(Common_ErrorsEnum.COMMON_6, "body不能为空");
        }
        if (StringUtils.isEmpty(body.getBkMeterId())) {
            throw new ServiceException(Common_ErrorsEnum.COMMON_6, "body.bkMeterId不能为空");
        }
        if (StringUtils.isEmpty(body.getBkMeterCode())) {
            throw new ServiceException(Common_ErrorsEnum.COMMON_6, "body.bkMeterCode不能为空");
        }
        if (StringUtils.isEmpty(body.getBkMeterTypeId())) {
            throw new ServiceException(Common_ErrorsEnum.COMMON_6, "body.bkMeterTypeId不能为空");
        }
        if (StringUtils.isEmpty(body.getDtuCode())) {
            throw new ServiceException(Common_ErrorsEnum.COMMON_6, "body.dtuCode不能为空");
        }
        if (StringUtils.isEmpty(body.getDtuTypeId())) {
            throw new ServiceException(Common_ErrorsEnum.COMMON_6, "body.dtuTypeId不能为空");
        }
        if (StringUtils.isEmpty(body.getGasUserCode())) {
            throw new ServiceException(Common_ErrorsEnum.COMMON_6, "body.gasUserCode不能为空");
        }
        if (StringUtils.isEmpty(body.getIotCompanyId())) {
            throw new ServiceException(Common_ErrorsEnum.COMMON_6, "body.iotCompanyId不能为空");
        }
        if (StringUtils.isEmpty(body.getGasCompanyId())) {
            throw new ServiceException(Common_ErrorsEnum.COMMON_6, "body.gasCompanyId不能为空");
        }
        if (StringUtils.isEmpty(body.getDeptId())) {
            throw new ServiceException(Common_ErrorsEnum.COMMON_6, "body.deptId不能为空");
        }

        Map<String, String> headerTmp = new HashMap<>();
        if (!StringUtils.isEmpty(header.get("_hzhr-company-id"))) {
            headerTmp.put("_hzhr-company-id", header.get("_hzhr-company-id"));
        }
        if (!StringUtils.isEmpty(header.get("_hzhr-dept-id"))) {
            headerTmp.put("_hzhr-dept-id", header.get("_hzhr-dept-id"));
        }
        if (!StringUtils.isEmpty(header.get("_hzhr-user-type"))) {
            headerTmp.put("_hzhr-user-type", header.get("_hzhr-user-type"));
        }
        if (!StringUtils.isEmpty(header.get("_hzhr-access-mode"))) {
            headerTmp.put("_hzhr-access-mode", header.get("_hzhr-access-mode"));
        }
        if (!StringUtils.isEmpty(header.get("_hzhr-user-name"))) {
            headerTmp.put("_hzhr-user-name", header.get("_hzhr-user-name"));
        }
        if (!StringUtils.isEmpty(header.get("_token"))) {
            headerTmp.put("_token", header.get("_token"));
        }
        if (!StringUtils.isEmpty(header.get("_hzhr-user-code"))) {
            headerTmp.put("_hzhr-user-code", header.get("_hzhr-user-code"));
        }
        if (!StringUtils.isEmpty(header.get("_hzhr-transaction-id"))) {
            headerTmp.put("_hzhr-transaction-id", header.get("_hzhr-transaction-id"));
        }
        if (!StringUtils.isEmpty(header.get("_hzhr-user-id"))) {
            headerTmp.put("_hzhr-user-id", header.get("_hzhr-user-id"));
        }
        if (!StringUtils.isEmpty(header.get("_hzhr-transaction-type"))) {
            headerTmp.put("_hzhr-transaction-type", header.get("_hzhr-transaction-type"));
        }
        if (!StringUtils.isEmpty(header.get("token"))) {
            headerTmp.put("_token", header.get("token"));
        }

        Map<String, Object> queryTmp = new HashMap<>();
        if (isInternalServiceInvok(headerTmp)) {
        } else {
        }

        if (isInternalServiceInvok(headerTmp)) {
            if (StringUtils.isEmpty(headerTmp.get("_token"))) {
                Map<String, Object> objectInfo = new HashMap<>();
                objectInfo.put("header", headerTmp);
                throw new ServiceException(Common_ErrorsEnum.COMMON_6, "header._token不能为空", objectInfo);
            }
            if (StringUtils.isEmpty(headerTmp.get("_hzhr-user-id"))) {
                Map<String, Object> objectInfo = new HashMap<>();
                objectInfo.put("header", headerTmp);
                throw new ServiceException(Common_ErrorsEnum.COMMON_6, "header._hzhr-user-id不能为空", objectInfo);
            }
            if (StringUtils.isEmpty(headerTmp.get("_hzhr-user-code"))) {
                Map<String, Object> objectInfo = new HashMap<>();
                objectInfo.put("header", headerTmp);
                throw new ServiceException(Common_ErrorsEnum.COMMON_6, "header._hzhr-user-code不能为空", objectInfo);
            }
            if (StringUtils.isEmpty(headerTmp.get("_hzhr-user-name"))) {
                Map<String, Object> objectInfo = new HashMap<>();
                objectInfo.put("header", headerTmp);
                throw new ServiceException(Common_ErrorsEnum.COMMON_6, "header._hzhr-user-name不能为空", objectInfo);
            }
            if (StringUtils.isEmpty(headerTmp.get("_hzhr-company-id"))) {
                Map<String, Object> objectInfo = new HashMap<>();
                objectInfo.put("header", headerTmp);
                throw new ServiceException(Common_ErrorsEnum.COMMON_6, "header._hzhr-company-id不能为空", objectInfo);
            }
            if (StringUtils.isEmpty(headerTmp.get("_hzhr-dept-id"))) {
                Map<String, Object> objectInfo = new HashMap<>();
                objectInfo.put("header", headerTmp);
                throw new ServiceException(Common_ErrorsEnum.COMMON_6, "header._hzhr-dept-id不能为空", objectInfo);
            }
            if (StringUtils.isEmpty(headerTmp.get("_hzhr-user-type"))) {
                Map<String, Object> objectInfo = new HashMap<>();
                objectInfo.put("header", headerTmp);
                throw new ServiceException(Common_ErrorsEnum.COMMON_6, "header._hzhr-user-type不能为空", objectInfo);
            }
            if (StringUtils.isEmpty(headerTmp.get("_hzhr-transaction-id"))) {
                Map<String, Object> objectInfo = new HashMap<>();
                objectInfo.put("header", headerTmp);
                throw new ServiceException(Common_ErrorsEnum.COMMON_6, "header._hzhr-transaction-id不能为空", objectInfo);
            }
            if (StringUtils.isEmpty(headerTmp.get("_hzhr-transaction-type"))) {
                Map<String, Object> objectInfo = new HashMap<>();
                objectInfo.put("header", headerTmp);
                throw new ServiceException(Common_ErrorsEnum.COMMON_6, "header._hzhr-transaction-type不能为空", objectInfo);
            }
            if (StringUtils.isEmpty(headerTmp.get("_hzhr-access-mode"))) {
                headerTmp.put("_hzhr-access-mode", "0");
            }
        } else {
            if (StringUtils.isEmpty(headerTmp.get("_token"))) {
                Map<String, Object> objectInfo = new HashMap<>();
                objectInfo.put("header", headerTmp);
                throw new ServiceException(Common_ErrorsEnum.COMMON_6, "header.token不能为空", objectInfo);
            }
        }

        if (!StringUtils.isEmpty(queryTmp.get("_is_paging")) && !Boolean.parseBoolean(queryTmp.get("_is_paging").toString())) {
            queryTmp.put("_page", null);
            queryTmp.put("_count", null);
        }
        args[1] = queryTmp;
        args[0] = headerTmp;
        return joinPoint.proceed(args);
    }
    @Around("execution(* com.hzhr.iot.device.service.BkMeterService.delete(..))")
    public Object delete(ProceedingJoinPoint joinPoint) throws Throwable {
        Object[] args = joinPoint.getArgs();
        Map<String, String> header = (Map<String, String>) args[0];
        if (header == null) {
            header = new HashMap<>();
        }
        Map<String, Object> query = (Map<String, Object>) args[1];
        if (query == null) {
            query = new HashMap<>();
        }

        BkMeterDeleteModel body = (BkMeterDeleteModel)args[2];
        if (body == null) {
            throw new ServiceException(Common_ErrorsEnum.COMMON_6, "body不能为空");
        }
        if (StringUtils.isEmpty(body.getBkMeterId())) {
            throw new ServiceException(Common_ErrorsEnum.COMMON_6, "body.bkMeterId不能为空");
        }

        Map<String, String> headerTmp = new HashMap<>();
        if (!StringUtils.isEmpty(header.get("_hzhr-company-id"))) {
            headerTmp.put("_hzhr-company-id", header.get("_hzhr-company-id"));
        }
        if (!StringUtils.isEmpty(header.get("_hzhr-dept-id"))) {
            headerTmp.put("_hzhr-dept-id", header.get("_hzhr-dept-id"));
        }
        if (!StringUtils.isEmpty(header.get("_hzhr-user-type"))) {
            headerTmp.put("_hzhr-user-type", header.get("_hzhr-user-type"));
        }
        if (!StringUtils.isEmpty(header.get("_hzhr-access-mode"))) {
            headerTmp.put("_hzhr-access-mode", header.get("_hzhr-access-mode"));
        }
        if (!StringUtils.isEmpty(header.get("_hzhr-user-name"))) {
            headerTmp.put("_hzhr-user-name", header.get("_hzhr-user-name"));
        }
        if (!StringUtils.isEmpty(header.get("_token"))) {
            headerTmp.put("_token", header.get("_token"));
        }
        if (!StringUtils.isEmpty(header.get("_hzhr-user-code"))) {
            headerTmp.put("_hzhr-user-code", header.get("_hzhr-user-code"));
        }
        if (!StringUtils.isEmpty(header.get("_hzhr-transaction-id"))) {
            headerTmp.put("_hzhr-transaction-id", header.get("_hzhr-transaction-id"));
        }
        if (!StringUtils.isEmpty(header.get("_hzhr-user-id"))) {
            headerTmp.put("_hzhr-user-id", header.get("_hzhr-user-id"));
        }
        if (!StringUtils.isEmpty(header.get("_hzhr-transaction-type"))) {
            headerTmp.put("_hzhr-transaction-type", header.get("_hzhr-transaction-type"));
        }
        if (!StringUtils.isEmpty(header.get("token"))) {
            headerTmp.put("_token", header.get("token"));
        }

        Map<String, Object> queryTmp = new HashMap<>();
        if (isInternalServiceInvok(headerTmp)) {
        } else {
        }

        if (isInternalServiceInvok(headerTmp)) {
            if (StringUtils.isEmpty(headerTmp.get("_token"))) {
                Map<String, Object> objectInfo = new HashMap<>();
                objectInfo.put("header", headerTmp);
                throw new ServiceException(Common_ErrorsEnum.COMMON_6, "header._token不能为空", objectInfo);
            }
            if (StringUtils.isEmpty(headerTmp.get("_hzhr-user-id"))) {
                Map<String, Object> objectInfo = new HashMap<>();
                objectInfo.put("header", headerTmp);
                throw new ServiceException(Common_ErrorsEnum.COMMON_6, "header._hzhr-user-id不能为空", objectInfo);
            }
            if (StringUtils.isEmpty(headerTmp.get("_hzhr-user-code"))) {
                Map<String, Object> objectInfo = new HashMap<>();
                objectInfo.put("header", headerTmp);
                throw new ServiceException(Common_ErrorsEnum.COMMON_6, "header._hzhr-user-code不能为空", objectInfo);
            }
            if (StringUtils.isEmpty(headerTmp.get("_hzhr-user-name"))) {
                Map<String, Object> objectInfo = new HashMap<>();
                objectInfo.put("header", headerTmp);
                throw new ServiceException(Common_ErrorsEnum.COMMON_6, "header._hzhr-user-name不能为空", objectInfo);
            }
            if (StringUtils.isEmpty(headerTmp.get("_hzhr-company-id"))) {
                Map<String, Object> objectInfo = new HashMap<>();
                objectInfo.put("header", headerTmp);
                throw new ServiceException(Common_ErrorsEnum.COMMON_6, "header._hzhr-company-id不能为空", objectInfo);
            }
            if (StringUtils.isEmpty(headerTmp.get("_hzhr-dept-id"))) {
                Map<String, Object> objectInfo = new HashMap<>();
                objectInfo.put("header", headerTmp);
                throw new ServiceException(Common_ErrorsEnum.COMMON_6, "header._hzhr-dept-id不能为空", objectInfo);
            }
            if (StringUtils.isEmpty(headerTmp.get("_hzhr-user-type"))) {
                Map<String, Object> objectInfo = new HashMap<>();
                objectInfo.put("header", headerTmp);
                throw new ServiceException(Common_ErrorsEnum.COMMON_6, "header._hzhr-user-type不能为空", objectInfo);
            }
            if (StringUtils.isEmpty(headerTmp.get("_hzhr-transaction-id"))) {
                Map<String, Object> objectInfo = new HashMap<>();
                objectInfo.put("header", headerTmp);
                throw new ServiceException(Common_ErrorsEnum.COMMON_6, "header._hzhr-transaction-id不能为空", objectInfo);
            }
            if (StringUtils.isEmpty(headerTmp.get("_hzhr-transaction-type"))) {
                Map<String, Object> objectInfo = new HashMap<>();
                objectInfo.put("header", headerTmp);
                throw new ServiceException(Common_ErrorsEnum.COMMON_6, "header._hzhr-transaction-type不能为空", objectInfo);
            }
            if (StringUtils.isEmpty(headerTmp.get("_hzhr-access-mode"))) {
                headerTmp.put("_hzhr-access-mode", "0");
            }
        } else {
            if (StringUtils.isEmpty(headerTmp.get("_token"))) {
                Map<String, Object> objectInfo = new HashMap<>();
                objectInfo.put("header", headerTmp);
                throw new ServiceException(Common_ErrorsEnum.COMMON_6, "header.token不能为空", objectInfo);
            }
        }

        if (!StringUtils.isEmpty(queryTmp.get("_is_paging")) && !Boolean.parseBoolean(queryTmp.get("_is_paging").toString())) {
            queryTmp.put("_page", null);
            queryTmp.put("_count", null);
        }
        args[1] = queryTmp;
        args[0] = headerTmp;
        return joinPoint.proceed(args);
    }
    @Around("execution(* com.hzhr.iot.device.service.BkMeterService.post(..))")
    public Object post(ProceedingJoinPoint joinPoint) throws Throwable {
        Object[] args = joinPoint.getArgs();
        Map<String, String> header = (Map<String, String>) args[0];
        if (header == null) {
            header = new HashMap<>();
        }
        Map<String, Object> query = (Map<String, Object>) args[1];
        if (query == null) {
            query = new HashMap<>();
        }

        BkMeterPostModel body = (BkMeterPostModel)args[2];
        if (body == null) {
            throw new ServiceException(Common_ErrorsEnum.COMMON_6, "body不能为空");
        }
        if (StringUtils.isEmpty(body.getBkMeterCode())) {
            throw new ServiceException(Common_ErrorsEnum.COMMON_6, "body.bkMeterCode不能为空");
        }
        if (StringUtils.isEmpty(body.getBkMeterTypeId())) {
            throw new ServiceException(Common_ErrorsEnum.COMMON_6, "body.bkMeterTypeId不能为空");
        }
        if (StringUtils.isEmpty(body.getDtuCode())) {
            throw new ServiceException(Common_ErrorsEnum.COMMON_6, "body.dtuCode不能为空");
        }
        if (StringUtils.isEmpty(body.getDtuTypeId())) {
            throw new ServiceException(Common_ErrorsEnum.COMMON_6, "body.dtuTypeId不能为空");
        }
        if (StringUtils.isEmpty(body.getGasUserCode())) {
            throw new ServiceException(Common_ErrorsEnum.COMMON_6, "body.gasUserCode不能为空");
        }
        if (StringUtils.isEmpty(body.getIotCompanyId())) {
            throw new ServiceException(Common_ErrorsEnum.COMMON_6, "body.iotCompanyId不能为空");
        }
        if (StringUtils.isEmpty(body.getGasCompanyId())) {
            throw new ServiceException(Common_ErrorsEnum.COMMON_6, "body.gasCompanyId不能为空");
        }
        if (StringUtils.isEmpty(body.getDeptId())) {
            throw new ServiceException(Common_ErrorsEnum.COMMON_6, "body.deptId不能为空");
        }

        Map<String, String> headerTmp = new HashMap<>();
        if (!StringUtils.isEmpty(header.get("_hzhr-company-id"))) {
            headerTmp.put("_hzhr-company-id", header.get("_hzhr-company-id"));
        }
        if (!StringUtils.isEmpty(header.get("_hzhr-dept-id"))) {
            headerTmp.put("_hzhr-dept-id", header.get("_hzhr-dept-id"));
        }
        if (!StringUtils.isEmpty(header.get("_hzhr-user-type"))) {
            headerTmp.put("_hzhr-user-type", header.get("_hzhr-user-type"));
        }
        if (!StringUtils.isEmpty(header.get("_hzhr-access-mode"))) {
            headerTmp.put("_hzhr-access-mode", header.get("_hzhr-access-mode"));
        }
        if (!StringUtils.isEmpty(header.get("_hzhr-user-name"))) {
            headerTmp.put("_hzhr-user-name", header.get("_hzhr-user-name"));
        }
        if (!StringUtils.isEmpty(header.get("_token"))) {
            headerTmp.put("_token", header.get("_token"));
        }
        if (!StringUtils.isEmpty(header.get("_hzhr-user-code"))) {
            headerTmp.put("_hzhr-user-code", header.get("_hzhr-user-code"));
        }
        if (!StringUtils.isEmpty(header.get("_hzhr-transaction-id"))) {
            headerTmp.put("_hzhr-transaction-id", header.get("_hzhr-transaction-id"));
        }
        if (!StringUtils.isEmpty(header.get("_hzhr-user-id"))) {
            headerTmp.put("_hzhr-user-id", header.get("_hzhr-user-id"));
        }
        if (!StringUtils.isEmpty(header.get("_hzhr-transaction-type"))) {
            headerTmp.put("_hzhr-transaction-type", header.get("_hzhr-transaction-type"));
        }
        if (!StringUtils.isEmpty(header.get("token"))) {
            headerTmp.put("_token", header.get("token"));
        }

        Map<String, Object> queryTmp = new HashMap<>();
        if (isInternalServiceInvok(headerTmp)) {
        } else {
        }

        if (isInternalServiceInvok(headerTmp)) {
            if (StringUtils.isEmpty(headerTmp.get("_token"))) {
                Map<String, Object> objectInfo = new HashMap<>();
                objectInfo.put("header", headerTmp);
                throw new ServiceException(Common_ErrorsEnum.COMMON_6, "header._token不能为空", objectInfo);
            }
            if (StringUtils.isEmpty(headerTmp.get("_hzhr-user-id"))) {
                Map<String, Object> objectInfo = new HashMap<>();
                objectInfo.put("header", headerTmp);
                throw new ServiceException(Common_ErrorsEnum.COMMON_6, "header._hzhr-user-id不能为空", objectInfo);
            }
            if (StringUtils.isEmpty(headerTmp.get("_hzhr-user-code"))) {
                Map<String, Object> objectInfo = new HashMap<>();
                objectInfo.put("header", headerTmp);
                throw new ServiceException(Common_ErrorsEnum.COMMON_6, "header._hzhr-user-code不能为空", objectInfo);
            }
            if (StringUtils.isEmpty(headerTmp.get("_hzhr-user-name"))) {
                Map<String, Object> objectInfo = new HashMap<>();
                objectInfo.put("header", headerTmp);
                throw new ServiceException(Common_ErrorsEnum.COMMON_6, "header._hzhr-user-name不能为空", objectInfo);
            }
            if (StringUtils.isEmpty(headerTmp.get("_hzhr-company-id"))) {
                Map<String, Object> objectInfo = new HashMap<>();
                objectInfo.put("header", headerTmp);
                throw new ServiceException(Common_ErrorsEnum.COMMON_6, "header._hzhr-company-id不能为空", objectInfo);
            }
            if (StringUtils.isEmpty(headerTmp.get("_hzhr-dept-id"))) {
                Map<String, Object> objectInfo = new HashMap<>();
                objectInfo.put("header", headerTmp);
                throw new ServiceException(Common_ErrorsEnum.COMMON_6, "header._hzhr-dept-id不能为空", objectInfo);
            }
            if (StringUtils.isEmpty(headerTmp.get("_hzhr-user-type"))) {
                Map<String, Object> objectInfo = new HashMap<>();
                objectInfo.put("header", headerTmp);
                throw new ServiceException(Common_ErrorsEnum.COMMON_6, "header._hzhr-user-type不能为空", objectInfo);
            }
            if (StringUtils.isEmpty(headerTmp.get("_hzhr-transaction-id"))) {
                Map<String, Object> objectInfo = new HashMap<>();
                objectInfo.put("header", headerTmp);
                throw new ServiceException(Common_ErrorsEnum.COMMON_6, "header._hzhr-transaction-id不能为空", objectInfo);
            }
            if (StringUtils.isEmpty(headerTmp.get("_hzhr-transaction-type"))) {
                Map<String, Object> objectInfo = new HashMap<>();
                objectInfo.put("header", headerTmp);
                throw new ServiceException(Common_ErrorsEnum.COMMON_6, "header._hzhr-transaction-type不能为空", objectInfo);
            }
            if (StringUtils.isEmpty(headerTmp.get("_hzhr-access-mode"))) {
                headerTmp.put("_hzhr-access-mode", "0");
            }
        } else {
            if (StringUtils.isEmpty(headerTmp.get("_token"))) {
                Map<String, Object> objectInfo = new HashMap<>();
                objectInfo.put("header", headerTmp);
                throw new ServiceException(Common_ErrorsEnum.COMMON_6, "header.token不能为空", objectInfo);
            }
        }

        if (!StringUtils.isEmpty(queryTmp.get("_is_paging")) && !Boolean.parseBoolean(queryTmp.get("_is_paging").toString())) {
            queryTmp.put("_page", null);
            queryTmp.put("_count", null);
        }
        args[1] = queryTmp;
        args[0] = headerTmp;
        return joinPoint.proceed(args);
    }
}

